package ${package}.${moduleName}.entity;

import lombok.Builder;
import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Builder;

<#list importList as i>
import ${i!};
</#list>
<#if baseClass??>
import ${baseClass.packageName}.${baseClass.code};
</#if>


<#if baseClass??>@EqualsAndHashCode(callSuper=false)</#if>

@Table(name = "${tableName}")
@Entity
@DynamicUpdate
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ${ClassName}<#if baseClass??> extends ${baseClass.code}</#if> extends Auditable{
<#list fieldList as field>
	<#if !field.baseField>
		<#if field.attrName != 'id' && field.attrName != 'createdAt' && field.attrName != 'createdBy' && field.attrName != 'updatedAt' && field.attrName != 'updatedBy'>
			<#if field.fieldComment!?length gt 0>
	/**
	 * ${field.fieldComment}
	 */
			</#if>
			<#if field.autoFill == "INSERT">
	@TableField(fill = FieldFill.INSERT)
			</#if>
			<#if field.autoFill == "INSERT_UPDATE">
	@TableField(fill = FieldFill.INSERT_UPDATE)
			</#if>
			<#if field.autoFill == "UPDATE">
	@TableField(fill = FieldFill.UPDATE)
			</#if>
			<#if field.primaryPk>
	@TableId
			</#if>
	private ${field.attrType} ${field.attrName};
		</#if>
	</#if>
</#list>

    public void edit(<#list fieldList as field>
			 <#if field.attrName != 'id' && field.attrName != 'createdAt' && field.attrName != 'createdBy' && field.attrName != 'updatedAt' && field.attrName != 'updatedBy'>
       ${field.attrType} ${field.attrName},  </#if></#list>){
         <#list fieldList as field>
			 <#if field.attrName != 'id' && field.attrName != 'createdAt' && field.attrName != 'createdBy' && field.attrName != 'updatedAt' && field.attrName != 'updatedBy'>
         this.${field.attrName} = ${field.attrName};
			 </#if>
         </#list>
    }

    public static ${ClassName} newInstance(<#list fieldList as field>${field.attrType}
<#if field.attrName != 'createdAt' && field.attrName != 'createdBy' && field.attrName != 'updatedAt' && field.attrName != 'updatedBy'>
				${field.attrName}, </#if> </#list>){
        return  ${ClassName}.builder()
         <#list fieldList as field>
			 	<#if field.attrName != 'createdAt' && field.attrName != 'createdBy' && field.attrName != 'updatedAt' && field.attrName != 'updatedBy'>
                .${field.attrName}(${field.attrName})
                </#if>
          </#list>
                .build();
    }
}